<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <div class="query-content">
        <el-form-item>
          <el-input
            v-model="queryParams.meetName"
            placeholder="请输入场地名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.groupId"
            placeholder="请选择企业"
            clearable
          >
            <el-option
              v-for="dict in dict.type.ly_group"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.projectId"
            placeholder="请选择项目"
            clearable
          >
            <el-option
              v-for="item in queryProjectList"
              :label="item.projectName"
              :value="item.id"
              :key="item.id"
            >
              {{ item.projectName }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.banId"
            placeholder="请选择楼栋"
            clearable
          >
            <el-option
              v-for="item in queryBanList"
              :label="item.banName"
              :value="item.banId"
              :key="item.banId"
            >
              {{ item.banName }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="queryParams.floorNumber"
            placeholder="请输入楼层"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.restType"
            placeholder="请选择场地类型"
          >
            <el-option
              v-for="dict in dict.type.rest_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.rentalType"
            placeholder="请选择租赁类型"
          >
            <el-option
              v-for="dict in dict.type.rental_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:meeting:add']"
          >创建功能场地</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:meeting:export']"
          >导出</el-button
        >
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="meetingList">
      <el-table-column type="index" label="序号" align="center" />
      <el-table-column label="名称" align="center" prop="meetName" />
      <el-table-column label="所属企业" align="center" prop="groupId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ly_group" :value="scope.row.groupId" />
        </template>
      </el-table-column>
      <el-table-column label="所属项目" align="center" prop="projectName" />
      <el-table-column label="楼栋" align="center" prop="banName" />
      <el-table-column label="楼层" align="center" prop="floorNumber" />
      <el-table-column label="场地类型" align="center" prop="restType">
        <template v-slot:default="scope">
          <dict-tag
            :options="dict.type.rest_type"
            :value="scope.row.restType"
          />
        </template>
      </el-table-column>
      <el-table-column label="租赁类型" align="center" prop="rentalType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.rental_type"
            :value="scope.row.rentalType"
          />
        </template>
      </el-table-column>
      <el-table-column label="容纳人数" align="center" prop="meetVolume" />
      <el-table-column label="面积" align="center" prop="meetArea" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateOrDetail(scope.row, '修改功能场地')"
            v-hasPermi="['project:meeting:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateOrDetail(scope.row, '功能场地详情')"
            v-hasPermi="['project:meeting:edit']"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:meeting:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改功能场地对话框 -->
    <el-dialog
      :fullscreen="true"
      :center="true"
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
    >
      <div class="dialog-content">
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          size="medium"
          label-width="110px"
        >
          <div class="top">
            <el-divider content-position="left">
              <span style="font-size: 20px">基本类型</span>
            </el-divider>
            <div class="top-content">
              <el-row :gutter="15">
                <el-col :span="24">
                  <el-row type="flex" justify="center" align="top" :gutter="15">
                    <el-col :span="24">
                      <el-form-item label="场地名称：" prop="meetName">
                        <el-input
                          v-model="form.meetName"
                          placeholder="请输入场地名称："
                          :maxlength="20"
                          clearable
                          :style="{ width: '100%' }"
                          :readonly="title === '功能场地详情'"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="场地类型：" prop="restType">
                        <el-select
                          v-model="form.restType"
                          placeholder="请选择场地类型："
                          :style="{ width: '100%' }"
                          :disabled="title === '功能场地详情'"
                        >
                          <el-option
                            v-for="dict in dict.type.rest_type"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          >
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="租赁类型：" prop="rentalType">
                        <el-select
                          v-model="form.rentalType"
                          placeholder="请选择租赁类型："
                          :style="{ width: '100%' }"
                          :disabled="title === '功能场地详情'"
                        >
                          <el-option
                            v-for="dict in dict.type.rental_type"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          >
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="24">
                  <el-row type="flex" justify="center" align="top" :gutter="15">
                    <el-col :span="24">
                      <el-form-item label="所属项目：" prop="projectId">
                        <div class="project_content">
                          <el-input
                            placeholder="点击查询"
                            :readonly="true"
                            v-model="form.projectName"
                          ></el-input>
                          <el-button
                            type="text"
                            class="project-select-button"
                            @click="projectSelect"
                            v-if="title !== '功能场地详情'"
                            >查询</el-button
                          >
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="所属楼栋：" prop="banId">
                        <el-select
                          v-model="form.banId"
                          placeholder="请选择所属楼栋："
                          :style="{ width: '100%' }"
                          @change="handleBanChange"
                          :disabled="title === '功能场地详情'"
                        >
                          <el-option
                            v-for="ban in banList"
                            :label="ban.banName"
                            :value="ban.banId"
                            >{{ ban.banName }}</el-option
                          >
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="所属楼层：" prop="floorNumber">
                        <el-select
                          v-model="form.floorNumber"
                          placeholder="请选择所属楼层："
                          :style="{ width: '100%' }"
                          :disabled="title === '功能场地详情'"
                        >
                          <el-option
                            v-for="item in floorList"
                            :label="item.floorNumber"
                            :value="item.floorNumber"
                            >{{ item.floorNumber }}
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="24">
                  <el-row type="flex" justify="center" align="top" :gutter="15">
                    <el-col :span="24">
                      <el-form-item label="预约单位：" prop="orderType">
                        <el-select
                          v-model="form.orderType"
                          placeholder="请选择预约单位："
                          :style="{ width: '100%' }"
                          :disabled="title === '功能场地详情'"
                        >
                          <el-option
                            v-for="item in orderType"
                            :label="item.label"
                            :value="item.value"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="可预约时段：" prop="orderTime">
                        <div class="orderTime">
                          <el-time-picker
                            v-model="form.orderStartTime"
                            format="HH:mm"
                            value-format="HH:mm"
                            size="small"
                            placeholder="开始时间"
                            clearable
                            :readonly="title === '功能场地详情'"
                          ></el-time-picker>
                          <span>至</span>
                          <el-time-picker
                            v-model="form.orderEndTime"
                            format="HH:mm"
                            value-format="HH:mm"
                            size="small"
                            placeholder="结束时间"
                            clearable
                            :readonly="title === '功能场地详情'"
                          ></el-time-picker>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="可取消时段：" prop="orderCancelTime">
                        <el-input
                          v-model="form.orderCancelTime"
                          placeholder="请输入可取消时段："
                          clearable
                          :style="{ width: '100%' }"
                          :readonly="title === '功能场地详情'"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="16">
                  <el-row type="flex" justify="center" align="top" :gutter="15">
                    <el-col :span="24">
                      <el-form-item label="容纳人数：" prop="meetVolume">
                        <el-input
                          v-model="form.meetVolume"
                          placeholder="请输入容纳人数："
                          clearable
                          :style="{ width: '100%' }"
                          :readonly="title === '功能场地详情'"
                        >
                          <template slot="append">人</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="面积：" prop="meetArea">
                        <el-input
                          v-model="form.meetArea"
                          placeholder="请输入面积："
                          clearable
                          :style="{ width: '100%' }"
                          :readonly="title === '功能场地详情'"
                        >
                          <template slot="append">m²</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="24">
                  <el-row :gutter="15">
                    <el-col :span="17">
                      <el-form-item label="设备配置：" prop="itemIds">
                        <el-checkbox-group
                          v-model="form.itemIds"
                          size="medium"
                          :disabled="title === '功能场地详情'"
                        >
                          <el-checkbox
                            v-for="dict in dict.type.ly_configuration"
                            :key="dict.value"
                            :label="dict.label"
                          />
                        </el-checkbox-group>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="16">
                  <el-row :gutter="15">
                    <el-col :span="24">
                      <el-form-item label="场地介绍：" prop="meetRemark">
                        <el-input
                          v-model="form.meetRemark"
                          placeholder="备注描述..."
                          clearable
                          :style="{ width: '100%' }"
                          :readonly="title === '功能场地详情'"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="16">
                  <el-row :gutter="15">
                    <el-col :span="24">
                      <el-form-item label="场地平面图：" required>
                        <el-upload
                          ref="file"
                          list-type="picture-card"
                          :file-list="fileList1"
                          :action="uploadUrl"
                          :on-success="
                            (response, file, fileList) =>
                              handleSuccess(
                                response,
                                file,
                                fileList,
                                'fileList1'
                              )
                          "
                          :on-remove="(file) => handleRemove(file, 'fileList1')"
                          :class="{ disabled: title === '功能场地详情' }"
                        >
                          <i class="el-icon-plus"></i>
                        </el-upload>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="16">
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="场地实景图：" required>
                        <el-upload
                          ref="file"
                          list-type="picture-card"
                          :file-list="fileList2"
                          :action="uploadUrl"
                          :on-success="
                            (response, file, fileList) =>
                              handleSuccess(
                                response,
                                file,
                                fileList,
                                'fileList2'
                              )
                          "
                          :on-remove="(file) => handleRemove(file, 'fileList2')"
                          :class="{ disabled: title === '功能场地详情' }"
                        >
                          <i class="el-icon-plus"></i>
                        </el-upload>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </div>
          </div>
          <div class="bottom">
            <el-divider content-position="left">
              <span style="font-size: 20px">套餐信息</span>
            </el-divider>
            <div class="bottom-content">
              <div
                class="package-information"
                v-for="index in menuList.length"
                :key="index"
              >
                <div class="package-item">
                  <el-row :gutter="15">
                    <el-col :span="12">
                      <el-form-item label="套餐名称：" prop="menuName">
                        <el-input
                          placeholder="例如：套餐A"
                          v-model="menuList[index - 1].menuName"
                          :readonly="title === '功能场地详情'"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="租赁单价：" prop="menuPrice">
                        <el-input
                          placeholder="请输入单价"
                          v-model="menuList[index - 1].menuPrice"
                          :readonly="title === '功能场地详情'"
                        >
                          <template slot="append">元/0.25h</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="简介：" prop="menuRemark">
                        <el-input
                          type="textarea"
                          :autosize="{ minRows: 4 }"
                          v-model="menuList[index - 1].menuRemark"
                          :readonly="title === '功能场地详情'"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <svg-icon
                    icon-class="close"
                    class-name="close-class"
                    @click="deleteMenu(index - 1)"
                    v-if="index > 1"
                  />
                </div>
              </div>
              <div class="addMenuBtn">
                <el-button
                  type="text"
                  class="addMenuBtn"
                  @click="addMenu"
                  v-if="title !== '功能场地详情'"
                  ><el-icon class="el-icon-plus" />添加套餐</el-button
                >
              </div>
            </div>
          </div>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="submitForm"
          v-if="title !== '功能场地详情'"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="项目查询器" width="60%" :visible.sync="openProjectSelect">
      <ProjectManagement ref="projectRef" :is-component="true" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelProjectSelect">取 消</el-button>
        <el-button type="primary" @click="confirmProjectSelect"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMeeting,
  getMeeting,
  delMeeting,
  addMeeting,
  updateMeeting,
  exportDataApi,
} from "@/api/space/meeting";
import ProjectManagement from "@/views/project/projectManagement/index.vue";
import {
  getAllBansApi,
  getAllProjectsApi,
  getBanByProjectId,
  getFloorsByProjectIdAndSiteGroupId,
} from "@/api/space/workSpace";

export default {
  name: "Meeting",
  components: { ProjectManagement },
  dicts: ["ly_group", "rest_type", "rental_type", "ly_configuration"],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工能场地表格数据
      meetingList: [],
      // 楼栋列表
      banList: [],
      // 楼层列表
      floorList: [],
      // 筛选条件的项目列表
      queryProjectList: [],
      // 用于查询的所有楼栋列表
      queryBanList: [],
      // 图片列表
      fileList1: [],
      fileList2: [],
      // 预约单位
      orderType: [
        { label: "15分钟", value: 15 },
        { label: "30分钟", value: 30 },
      ],
      // 文件上传地址
      uploadUrl: process.env.VUE_APP_BASE_API + "/ly/fileUpload",
      // 套餐列表
      menuList: [{ menuName: null, menuPrice: null, menuRemark: null }],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 项目选择器弹出层
      openProjectSelect: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        groupId: null,
        projectId: null,
        meetName: null,
        restType: null,
        rentalType: null,
        banId: null,
        floorNumber: null,
      },
      // 表单参数
      form: {
        meetName: null,
        restType: null,
        rentalType: null,
        projectId: null,
        banId: null,
        floorNumber: null,
        orderType: null,
        orderStartTime: null,
        orderEndTime: null,
        orderCancelTime: null,
        meetVolume: null,
        meetArea: null,
        itemIds: [],
        meetRemark: null,
        // imgs1: [],
        // imgs2: [],
        meunInfo: [
          { menuId: null, menuName: null, menuPrice: null, menuRemark: null },
        ],
      },
      // 表单校验
      rules: {
        projectId: [{ required: true, message: "请选择项目", trigger: "blur" }],
        orderStartTime: [
          { required: true, message: "预约开始时间", trigger: "blur" },
        ],
        orderEndTime: [
          { required: true, message: "预约结束时间", trigger: "blur" },
        ],
        meetName: [
          {
            required: true,
            message: "请输入场地名称：",
            trigger: "blur",
          },
        ],
        restType: [
          {
            required: true,
            message: "请输入场地类型：",
            trigger: "blur",
          },
        ],
        rentalType: [
          {
            required: true,
            message: "请输入租赁类型：",
            trigger: "blur",
          },
        ],
        banId: [
          {
            required: true,
            message: "请选择所属楼栋：",
            trigger: "change",
          },
        ],
        floorNumber: [
          {
            required: true,
            message: "请选择所属楼层：",
            trigger: "change",
          },
        ],
        orderType: [
          {
            required: true,
            message: "请选择预约单位：",
            trigger: "change",
          },
        ],
        orderCancelTime: [
          {
            required: true,
            message: "请输入可取消时段：",
            trigger: "blur",
          },
        ],
        meetVolume: [
          {
            required: true,
            message: "请输入容纳人数：",
            trigger: "blur",
          },
        ],
        meetArea: [
          {
            required: true,
            message: "请输入面积：",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    // 查询所有项目列表
    this.getAllProjects();
    // 查询所有楼栋列表
    this.getAllBans();
  },
  methods: {
    /** 查询功能场地 */
    getList() {
      this.loading = true;
      listMeeting(this.queryParams).then((response) => {
        this.meetingList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        meetName: null,
        restType: null,
        rentalType: null,
        projectId: null,
        banId: null,
        floorNumber: null,
        orderType: null,
        orderStartTime: null,
        orderEndTime: null,
        orderCancelTime: null,
        meetVolume: null,
        meetArea: null,
        itemIds: [],
        meetRemark: null,
        imgs1: [],
        imgs2: [],
        meunInfo: [
          { menuId: null, menuName: null, menuPrice: null, menuRemark: null },
        ],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        groupId: null,
        projectId: null,
        meetName: null,
        restType: null,
        rentalType: null,
        banId: null,
        floorNumber: null,
      };
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加功能场地";
    },
    transDataBeforeSubmit() {
      // 基础设备转换
      this.form.itemIds = JSON.stringify(this.form.itemIds);
      // 图片转换
      this.form.imgs1 = JSON.stringify(this.form.imgs1);
      this.form.imgs2 = JSON.stringify(this.form.imgs2);
      // 套餐信息转换
      this.form.meunInfo = JSON.stringify(this.menuList);
    },
    transDataAfterRev(response) {
      // 基础设备转换
      this.form.itemIds = JSON.parse(this.form.itemIds);
      // 图片转换
      this.form.imgs1 = this.fileList1 = JSON.parse(response.data.imgs1);
      this.form.imgs2 = this.fileList2 = JSON.parse(response.data.imgs2);
      // 套餐信息转换
      this.form.meunInfo = this.menuList = JSON.parse(response.data.meunInfo);
    },
    /** 修改/详情按钮操作 */
    handleUpdateOrDetail(row, title) {
      this.reset();
      const meetId = row.meetId;
      getMeeting(meetId).then((response) => {
        this.form = response.data;
        this.form.meetId = meetId;
        this.transDataAfterRev(response);
        // 获取对应楼栋和楼层
        this.getBanList(this.form.projectId);
        this.getFloorList(this.form.projectId, this.form.banId);

        this.open = true;
        this.title = title;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // 转换部分数据的格式
          this.transDataBeforeSubmit();
          if (this.form.meetId != null) {
            updateMeeting(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMeeting(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const meetIds = row.meetId || this.ids;
      this.$modal
        .confirm('是否确认删除[空间] 会议室编号为"' + meetIds + '"的数据项？')
        .then(function () {
          return delMeeting(meetIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      exportDataApi().then((res) => {
        // 创建 Blob 对象，用于包含二进制数据
        const blob = new Blob([res]);
        // 创建 a 标签元素，并将 Blob 对象转换成 URL
        const link = document.createElement("a");
        link.href = window.URL.createObjectURL(blob);
        // 设置下载文件的名称
        const date = new Date();
        const now = date.toLocaleDateString();
        link.download = "功能场地数据_" + now + "_.xlsx";
        // 模拟点击下载链接
        link.click();
      });
    },
    onClose() {
      this.$refs["form"].resetFields();
    },
    close() {
      this.$emit("update:visible", false);
    },
    handleConfirm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) return;
        this.close();
      });
    },
    /** 添加套餐 */
    addMenu() {
      this.menuList.push({
        menuName: null,
        menuPrice: null,
        menuRemark: null,
      });
      console.log(this.menuList);
    },
    /** 删除工位 */
    deleteMenu(index) {
      this.menuList.splice(index, 1);
    },
    /** 查询项目信息 */
    projectSelect() {
      this.openProjectSelect = true;
    },
    /** 取消查询项目信息 */
    cancelProjectSelect() {
      this.openProjectSelect = false;
      this.$refs.projectRef.reset();
    },
    /** 确认项目 */
    confirmProjectSelect() {
      const currentProject = this.$refs.projectRef.getCurrentProject();
      this.form.projectName = currentProject.projectName;
      this.form.projectId = currentProject.id;
      this.form.groupId = currentProject.groupId;
      // 获取该项目的所有楼栋信息
      this.getBanList(this.form.projectId);
      // 清空楼栋和楼层的初始值
      this.form.banId = null;
      this.form.floorNumber = null;
      this.floorList = [];

      this.openProjectSelect = false;
      this.$refs.projectRef.reset();
    },
    handleSuccess(response, file, fileList, type) {
      const fileObject = {};
      fileObject.name = file.name;
      fileObject.url = response.data;
      //场地平面图
      if (type === "fileList1") {
        this.form.imgs1.push(fileObject);
      } else {
        this.form.imgs2.push(fileObject);
      }
    },
    handleRemove(file, type) {
      if (type === "fileList1") {
        this.form.img1 = this.form.imgs1.filter(
          (item) => item.name !== file.name
        );
      } else {
        this.form.imgs2 = this.form.imgs2.filter(
          (item) => item.name !== file.name
        );
      }
    },
    /** 获取楼栋列表 */
    getBanList(projectId) {
      getBanByProjectId(projectId).then((res) => {
        this.banList = res.code === 200 ? res.data : [];
      });
    },
    /** 获取楼层列表 */
    getFloorList(projectId, banId) {
      getFloorsByProjectIdAndSiteGroupId(projectId, banId).then((res) => {
        this.floorList = res.code === 200 ? res.data : [];
      });
    },
    /** 楼栋变化函数 */
    handleBanChange(val) {
      // 获取当前楼栋下的楼层
      this.getFloorList(this.form.projectId, val);
    },
    /** 查询所有项目列表用于筛选 */
    getAllProjects() {
      getAllProjectsApi().then((res) => {
        this.queryProjectList = res.code === 200 ? res.data : [];
      });
    },
    /** 查询所有楼栋列表用于筛选 */
    getAllBans() {
      getAllBansApi().then((res) => {
        this.queryBanList = res.code === 200 ? res.data : [];
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.query-content {
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.el-upload__tip {
  line-height: 1.2;
}

.package-information {
  background-color: #fcf7e4;
  padding: 10px;
  position: relative;

  .package-item {
    width: 60%;
    display: flex;

    .close-class {
      position: absolute;
      right: -6px;
      top: -6px;
    }
  }
}

.addMenuBtn {
  margin-top: 10px;
  text-align: center;
}

.project_content {
  display: flex;
  align-items: center;
  position: relative;

  .project-select-button {
    position: absolute;
    right: 10px;
  }
}

.orderTime {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.disabled .el-upload--picture-card {
  display: none;
}
</style>
